<?xml version="1.0" encoding="UTF-8" ?>

<!-- 
One XLST that use HTML + CSS to display a table with all the teams showing 
for each team, the club name, the current score, the number of games, the 
number of wins, number of ties, and number of loses, the number of goals 
scored and the number of goals conceded, and the average of goals scored 
and conceded. The XSLT should receive two parameters, one to indicate the 
column to be used to sort and the other to indicate sort direction. 
 -->

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

	<xsl:output method="html" indent="yes"/>
    
	<xsl:param name="columnSort">points</xsl:param>
	<xsl:param name="dataType">number</xsl:param>
	<xsl:param name="sortOrder">descending</xsl:param>
	<xsl:param name="type" select="'html'"/>
	<xsl:param name="query"/>
	
	<xsl:template match="/">
	
	 <xsl:choose>
            <xsl:when test="$type = 'html'">
		   <html>
		      <head>
					<title>XpertStats XML - Tabela Classificativa</title>
					<link href="css/bluedream.css" media="screen" rel="stylesheet" type="text/css" />
					<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
					<link rel="shortcut icon" href="images/logo.ico" />
					<link rel="icon" type="image/gif" href="images/logo.ico" />
					
					<script type="text/javascript">
						var columnSort = '<xsl:value-of select="$columnSort"/>';
						var sortOrder = '<xsl:value-of select="$sortOrder"/>';
						var dataType = '<xsl:value-of select="$dataType"/>';
					 	var query = '<xsl:value-of select="$query"/>';
					 	var xslFile = "xslt/teams_page.xslt";
					 	var xmlFile = "teams_data.xml"
					</script>
					<script type="text/javascript" src="js/XSLT-sort.js"/> 
				</head>
				<body>
					<div id="wrapper">
						<div id="header">
							<div id="header_content">
								<img src="./images/logo.png"/>
								<div style="float:right">
								   
								</div>
							</div>
						</div>  
						<div id="menuStrip">
							<ul class="menu">
								  <li><a href="stadiums_data.xml"><span>Stadiums</span></a></li>
								  <li><a href="teams_data.xml" class="active"><span>Teams</span></a></li>
								  <li><a href="players_data.xml"><span>Players</span></a></li>
								  <li><a href="fixtures_data.xml"><span>Fixtures</span></a></li>
							</ul>    
						</div>
			
            
                      <xsl:apply-templates select="teams"/>
                      
					   
				</div>
				<div id="footer">
					<div id="footerD">
						<div id="footerF" class="aligned">XpertStats XML - Desenvolvido no âmbito da cadeira CTXML 2011 @ FCT-UNL</div>
						<div id="footerS" class="aligned">Por: Ricardo Mestre e Nuno Gomes</div>
					</div>
				</div>    
			</body>
		</html>
		</xsl:when>
           <xsl:otherwise>
                <xsl:apply-templates select="teams"/>
            </xsl:otherwise>
        </xsl:choose>
	</xsl:template>








    <xsl:template match="teams">
        <div id="main" style="padding-top: 10px;">   
		  <table border="1" width="100%" class="geral">
			<thead>
				<tr>
					<th style="text-align:center;" colspan="2">
						<a href="javascript:sortColumn('name')">
						<xsl:attribute name="title">ordena por nome</xsl:attribute>
						Equipa
						</a>
					</th>
					<th style="text-align:center; width:20px">
						<a href="javascript:sortColumn('points')">
						<xsl:attribute name="title">ordena por número de pontos</xsl:attribute>
						Pts
						</a>
					</th>
					<th style="text-align:center; width:20px">
						<a href="javascript:sortColumn('gamesPlayed')">
						<xsl:attribute name="title">ordena por número de jogos</xsl:attribute>
						J
						</a>
					</th>
					<th style="text-align:center; width:20px">
						<a href="javascript:sortColumn('wins')">
						<xsl:attribute name="title">ordena por número de vitorias</xsl:attribute>
						V
						</a>
					</th>
					<th style="text-align:center; width:20px">
						<a href="javascript:sortColumn('draws')">
						<xsl:attribute name="title">ordena por número de empates</xsl:attribute>
						E
						</a>
					</th>
					<th style="text-align:center; width:20px">
						<a href="javascript:sortColumn('loses')">
						<xsl:attribute name="title">ordena por número de derrotas</xsl:attribute>
						D
						</a>
					</th>
					<th style="text-align:center; width:20px">
						<a href="javascript:sortColumn('goalsScored')">
						<xsl:attribute name="title">ordena por golos marcados</xsl:attribute>
						GM
						</a>
					</th>
					<th style="text-align:center; width:20px">
						<a href="javascript:sortColumn('goalsConceded')">
						<xsl:attribute name="title">ordena por golos sofridos</xsl:attribute>
						GS
						</a>
					</th>
					<th style="text-align:center; width:20px">
						<xsl:attribute name="title">ordena por média golos marcados</xsl:attribute>
						MGM
					</th>
					<th style="text-align:center; width:20px">
						<xsl:attribute name="title">ordena por média golos sofridos</xsl:attribute>
						MGS
					</th>
				</tr>
			</thead>
            
            <tbody>
		      <xsl:for-each select="team">
		      
			     <xsl:sort 
					 select="*[name(.)=$columnSort]|@*[name(.)=$columnSort]" 
			         order="{$sortOrder}"  data-type="{$dataType}" />
			     

        		<tr>
                    <td style="text-align:center;"> 
        			<img>
        				<xsl:attribute name="src">images/teams/s<xsl:value-of select=" count(preceding-sibling::*) + 1"/>.png</xsl:attribute>
        				<xsl:attribute name="border">0</xsl:attribute>
        			 </img>
        	       	</td>
        	      	<td><a href="javascript:viewTeam('{@id}')"><xsl:value-of select="name"/></a></td>
        	      	<td style="text-align:center"><xsl:value-of select="points"/></td>
        	      	<td style="text-align:center"><xsl:value-of select="gamesPlayed"/></td>
        	      	<td style="text-align:center"><xsl:value-of select="wins"/></td>
        	      	<td style="text-align:center"><xsl:value-of select="draws"/></td>
        	      	<td style="text-align:center"><xsl:value-of select="loses"/></td>
        	      	<td style="text-align:center"><xsl:value-of select="goalsScored"/></td>
        	      	<td style="text-align:center"><xsl:value-of select="goalsConceded"/></td>
        	      	<td style="text-align:center;"><xsl:value-of select="avgGoalsScored"/></td>
                    <td style="text-align:center;"><xsl:value-of select="avgGoalsConceded"/></td>
        	   </tr>
        	</xsl:for-each>
        </tbody>
		</table>	
    </div>
</xsl:template>


</xsl:stylesheet>
